package grammaire;


import lexparser.logoLexer;
import lexparser.logoParser;
import lexparser.logoParser.prog_return;
import mem.Mem;
import mem.interfaces.IMem;

import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;

import tools.FileUtils;

import environnement.Env;
import environnement.interfaces.IEnv;

public class test1 {
	public static void main(String[] args) {
		
		try {
			
			/* Initialisation */
			IEnv e = new Env();
			IMem m = new Mem();
			
			/* Parse */
			String commandes = FileUtils.lecture_fichier("exemples/exemple-6");
			CharStream stream = new ANTLRStringStream(commandes);
			logoLexer lexer = new logoLexer(stream);
			CommonTokenStream tokenStream = new CommonTokenStream(lexer);
			logoParser parser = new logoParser(tokenStream);
			prog_return prog = parser.prog();
			
			//Evaluation de l'arbre
			prog.e.eval(null,e, m);
			
			System.out.println("\n**AST**");
			System.out.println(prog.e.toTreeString("",e,m));
			System.out.println("\n**ENVIRONNEMENT**");
			System.out.println(e.toString());
			System.out.println("**MEMOIRE**");
			System.out.println(m.toString());

			
		} catch (RecognitionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
